import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_mode/ui/iosui_demo.dart';
import 'package:flutter_mode/ui/localizations.dart';
import 'package:flutter_mode/ui/material_demo.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

import 'generated/l10n.dart';

class MyHomePage extends StatefulWidget {
  MyHomePage({Key? key}) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage>
    with AutomaticKeepAliveClientMixin {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {

    var ii = Image.asset("assets/img/girl_header.jpg", fit: BoxFit.fill);

    return Scaffold(
      body: CustomScrollView(
        slivers: <Widget>[
          const SliverAppBar(
            pinned: true,
            automaticallyImplyLeading: false,
            expandedHeight: 250.0,
            flexibleSpace: FlexibleSpaceBar(
              title: Text('Demo'),
              centerTitle: true,
              background: const Image(image: NetworkImage("https://www.yimizi.xyz/wedding/image/only/11.webp")),
            ),
            // shape: CircleBorder(side: BorderSide(color: Colors.yellow)),
          ),
          SliverList(
              delegate: SliverChildListDelegate(<Widget>[
            Center(
              heightFactor: 2,
              child: Text(
                '计数： $_counter',
                style: Theme.of(context).textTheme.headlineMedium,
              ),
            ),
            Row(
              children: <Widget>[
                ElevatedButton(
                  onPressed: () {
                    Navigator.push(context,
                        MaterialPageRoute(builder: (context) {
                      return MaterialScreen();
                    }));
                  },
                  child: Text('更多material风'),
                ),
                CupertinoButton(
                    child: Text('去看iOS风'),
                    onPressed: () {
                      Navigator.push(context,
                          MaterialPageRoute(builder: (context) {
//                            return IOSUIScreen();
                        // TODO 启用IOS风 需要使用CupertinoApp，同理Material风需要MaterialApp
                        return CupertinoApp(
                          title: 'flutter Demo iOS Style',
                          home: IOSUIScreen(),

                          // 本地化配置，平台控件默认使用英文，这里设置为首选中午。Cupertiono没有提供中午，所有这里使用了自定义的本地化文件
                          localizationsDelegates: [
                            S.delegate,
                            MyCupertinoLocalizations.delegate,
                            GlobalMaterialLocalizations.delegate,
                            GlobalWidgetsLocalizations.delegate
                          ],
                          // supportedLocales: S.delegate.supportedLocales,
                          supportedLocales: [
                            Locale('zh', 'CN'),
                            Locale('en', 'US')
                          ],
                          // localeResolutionCallback:
                          // S.delegate.resolution(fallback: new Locale("zh", "")),
                        );
                      }));
                    },
                    color: Colors.blue)
              ],
            ),
            // TODO material 风格控件
            Divider(),
            Stepper(
              steps: <Step>[
                Step(
                    title: Text('step title'),
                    content: Text('step cotent'),
                    isActive: true),
                Step(
                    title: Text('Stepper'),
                    isActive: true,
                    content: Text(
                        'A Material Design stepper widget that displays progress through a sequence of steps.')),
                Step(
                    title: Text('step title'),
                    content: Text('step cotent'),
                    isActive: true),
              ],
              onStepCancel: null,
              onStepContinue: null,
            )
          ])),
          SliverGrid(
            gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
              maxCrossAxisExtent: 200.0,
              mainAxisSpacing: 10.0,
              crossAxisSpacing: 10.0,
              childAspectRatio: 4.0,
            ),
            delegate: SliverChildBuilderDelegate(
              (BuildContext context, int index) {
                return Container(
                  alignment: Alignment.center,
                  color: Colors.teal[100 * (index % 9)],
                  child: Text('grid item $index'),
                );
              },
              childCount: 20,
            ),
          ),
          SliverFixedExtentList(
            itemExtent: 50.0,
            delegate:
                SliverChildBuilderDelegate((BuildContext context, int index) {
              return Container(
                alignment: Alignment.center,
                color: Colors.lightBlue[100 * (index % 9)],
                child: Text('list item $index'),
              );
            }, childCount: 30),
          ),
        ],
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }

  @override
  // TODO: implement wantKeepAlive
  bool get wantKeepAlive => true;
}
